<template>
  <div>
    <router-link to="/">
      <div
      class="header-abs"
      v-show="showAbs"
      >
        <div class="iconfont header-abs-back-icon">&#xe685;</div>
      </div>
    </router-link>
    <div
    class="header-fixed"
    v-show="!showAbs"
    :style="opacityStyle"
    >
      景点详情
      <router-link to="/">
        <div class="iconfont header-fixed-back">&#xe685;</div>
      </router-link>
    </div>
  </div>
</template>

<script>
import CommonGallary from "common/gallary/Gallary";
export default {
  name: "DetailHeader",
  data() {
    return {
      showAbs:true,
      opacityStyle:{
        opacity:0
      }
    }
  },
  methods:{
    handleScroll(){
      // 适配
      const top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      if(top>40){
        let opacity = top/140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {
          opacity
        }
        this.showAbs = false
      }else{
        this.showAbs = true
      }
    }
  },
  activated(){
    window.addEventListener('scroll',this.handleScroll)
  },
  deactivated() {
    window.removeEventListener('scroll',this.handleScroll)
  },
};
</script>

<style lang="less" scoped>
@import "~@/assets/styles/varibles.less";
.header-abs {
  position: absolute;
  left: 0.2rem;
  top: 0.2rem;
  width: 0.6rem;
  height: 0.6rem;
  line-height: 0.6rem;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.8);
  border-radius: 0.4rem;
  .header-abs-back-icon {
    color: #fff;
    font-size: 0.4rem;
  }
}
.header-fixed {
  z-index: 2;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  // overflow: hidden;
  height: 0.86rem;
  line-height: 0.86rem;
  text-align: center;
  color: #fff;
  background-color: @bacc;
  font-size: 0.3rem;
  .header-fixed-back{
    position: absolute;
    top: 0;
    left: .12rem;
    text-align: center;
    font-size: .4rem;
    color: #fff;
  }
}
</style>
